<!doctype html>
<html>
<head>

    <!--会员编辑-->

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <title>AI</title>
    <link type="text/css" rel="stylesheet" href="style/index.css">
    <link type="text/css" rel="stylesheet" href="style/reset.css">
    <link type="text/css" rel="stylesheet" href="style/swiper.min.css">
    <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="js/path.js"></script>
    <script type="text/javascript" src="js/md5.js"></script>
</head>


<script>

    var tagsint = new Array();
    var tagsname = new Array();
    var customername = '';
    var id = window.localStorage.getItem("id");
    var peplo = '';
    $(function () {
        querycustomer(id);
    });


    function querycustomer(id) {
        map.ids = id;
        var sign= $.md5(jsonSort(map)+token+time+time);
        map.sign=sign.toUpperCase();
        $.get(path + '/v1/customer/ids', map , function (res) {
            var tagsname = "";

            for (var tagsnum = 0; tagsnum < res.data.tags.length; tagsnum++) {
                tagsint[tagsnum] = res.data.tags[tagsnum].id;
                tagsname += res.data.tags[tagsnum].name + "  ";
            }


            document.getElementById('costomerphoto').src = res.data.imgUrl;
            $("#name").val(res.data.name);
            customername = res.data.name;
            $("#age").val(res.data.age);
            $("#gender").val(res.data.gender);
            $("#mobile").val(res.data.mobile);
            $("#email").val(res.data.email);
            $("#address").val(res.data.address);
            $("#tags").val(tagsname);
            $("#level").val(res.data.level);
            $("#interest").val(res.data.interestName);


        }, 'json');
    }

    //取消修改按钮
    function cancel() {
        location.href = 'customermanage.html';
    }

    //点击标签窗口
    function tagswindow() {
        //显示修改标签窗口
        $("#tagslist").show();
        //查询自己拥有的标签渲染在窗口下方
        $("#mask").show();
        mytags();
        //查询数据库中所有的标签渲染在窗口上方
        dbtags();
    }


    //查询自己拥有的标签渲染在窗口上方
    function mytags() {
        var sign= $.md5(jsonSort(map)+token+time+time);
        map.sign=sign.toUpperCase();
        map.customerid=parseInt(window.localStorage.getItem("id"));
        $.get(path + '/v1/tags/querytagsforcustomerid', map, function (res) {
            for (var tagnum = 0; tagnum < res.data.length; tagnum++) {
                tagsname[tagnum] = res.data[tagnum].name;
                $("#mytags").append("<li class='item' ondblclick='deletetags(" + res.data[tagnum].id + ")' ><a href='#'>" + res.data[tagnum].name + "</a></li>");
            }

        }, 'json');

    }


    //查询数据库中所有的标签渲染在窗口下方
    function dbtags() {
        var sign= $.md5(jsonSort(map)+token+time+time);
        map.sign=sign.toUpperCase();
        $.get(path + '/v1/tags', map, function (res) {
            for (var tagnum = 0; tagnum < res.data.length; tagnum++) {
                if (!tagsname.includes(res.data[tagnum].name)) {
                    $("#dbtags").append("<li class='item' ondblclick='addtags(" + res.data[tagnum].id + ")' ><a href='#'>" + res.data[tagnum].name + "</a></li>");
                }
            }
        }, 'json');
    }


    //双击数据库中的标签（新增进入已知用户的标签中）
    function addtags(index) {
        map.customerId=parseInt(window.localStorage.getItem("id"));
        map.tagId=index;
        var sign= $.md5(jsonSort(map)+token+time+time);
        map.sign=sign.toUpperCase();
        $.post(path + "/v1/customertags/addcustomertags",map, function (res) {
            if (res.code == 0) {
                $("#mytags").html("");
                $("#dbtags").html("");
                mytags();
                dbtags();
                querycustomer(id);
            } else {
                $("#mytags").html("");
                $("#dbtags").html("");
                mytags();
                dbtags();
                querycustomer(id);
            }
        }, 'json');
    }


    //双击用户的标签（删除双击的当前的标签）
    function deletetags(index) {
        map.customerId=parseInt(window.localStorage.getItem("id"));
        map.tagId=index;
        var sign= $.md5(jsonSort(map)+token+time+time);
        map.sign=sign.toUpperCase();
        $.post(path + "/v1/customertags/deletecustomertags", map, function (res) {
            if (res.code == 0) {
                $("#mytags").html("");
                $("#dbtags").html("");
                mytags();
                dbtags();
                querycustomer(id);
            } else {
                $("#mytags").html("");
                $("#dbtags").html("");
                mytags();
                dbtags();
                querycustomer(id);
            }
        }, 'json');
    }


    //点击新增弹出新增窗口
    function addtagscustomer() {
        $("#addtagscustom").show();
        $("#customername").val(customername);
    }


    //点击更换头像
    function changepic() {
        var reads = new FileReader();
        f = document.getElementById('cudtomerimg').files[0];
        reads.readAsDataURL(f);
        reads.onload = function (e) {
            document.getElementById('costomerphoto').src = this.result;
        };

        var formData = new FormData();
        formData.append("file", $("#cudtomerimg")[0].files[0]);
        formData.append("timestamp", time);
        formData.append("nonce", time);
        formData.append("token", token);

        var sign= $.md5(token+time+time);
        formData.append("sign", sign.toUpperCase());

        $.ajax({
            url: path + "/v1/customer/upload",
            type: 'POST',
            data: formData,
            processData: false,
            contentType: false,
            success: function (data) {
                peplo = data.data;
            }
        });
    }

    //新增保存按钮
    function addtagscustomercommit() {
        map.name=$("#tagsname").val();
        map.customerId=parseInt(window.localStorage.getItem("id"));
        var sign= $.md5(jsonSort(map)+token+time+time);
        map.sign=sign.toUpperCase();
        $.post(path + "/v1/customertags/addtagscustomer",map, function (res) {
            if (res.code == 0) {
                confirm("新增成功");
                querycustomer(id);
                $("#ullist input").val("");
                $("#addtagscustom").hide();
            } else {
                confirm("新增失败");
            }
        }, "json");
    }


    //关闭新增分组的窗口
    function closeaddgrouping() {
        $("#addtagscustom").hide();
    }


    //关闭设置标签的窗口
    function guanbi() {
        $("#tagslist").hide();
        $("#mask").hide();
        $("#dbtags").html("");
        $("#mytags").html("");
    }

    //修改会员
    function affirm() {
        var name = $("#name").val();
        map.id=window.localStorage.getItem("id");
        map.level=$("#level").val();
        map.name=name;
        map.age=$("#age").val();
        map.mobile=$("#mobile").val();
        map.gender=$("#gender").val();
        map.email=$("#email").val();
        map.address=$("#address").val();
        if(peplo!=""){
            map.imgUrl=peplo;
        }
        map.interestName=$("#interest").val();
        var sign= $.md5(jsonSort(map)+token+time+time);
        map.sign=sign.toUpperCase();
        $.ajax({
            url: path + "/v1/customer/update",
            type: 'POST',
            data:map ,
            success: function (response) {
                if (response.code == 0) {
                    confirm("修改成功");
                    location.href = 'customermanage.html';
                } else {
                    confirm("修改失败");
                }
            },
        });
    }


</script>


<body>
<header class="inhead-box">
    <div class="inhead"><a href="#" class="logo abe-fl">人脸识别系统</a>
        <div class="user-info abe-fr"><span><em class="vi-green">admin</em>，您好！ </span> <a href="#" class="uhead"><img
                src="images/user_head.jpg" alt=""></a></div>
        <nav class="abe-fr"><a href="customermanage.html" class="active">会员管理</a><a href="dataanalysis.html">数据分析</a><a
                href="aishow.html">AI显示</a><a
                href="systemsettings.html">系统设置</a><a href="extendmodule.html">扩展模块</a></nav>
    </div>
</header>
<div class="blank20"></div>
<div class="main">
    <div class="menu abe-fl">
        <h1 class="title"><a href="index.html"><i class="iconfont abe-ft24 mrg_10">&#xe601;</i>回首页</a></h1>
        <ul>
            <li class="active"><a href="customermanage.html"><i class="iconfont">&#xe73c;</i>会员管理</a></li>
            <li><a href="informationpush.html"><i class="iconfont">&#xe600;</i>信息推送</a></li>
            <li><a href="othersettings.html"><i class="iconfont">&#xe660;</i>其他设置</a></li>
        </ul>
    </div>

    <div class="content abe-fr">
        <div class="local"> 当前位置<em class="abe-space">&gt;</em><span class="abe-gray3">会员信息编辑</span></div>

        <div class="user-form">
            <div class="blank20"></div>

            <ul class="user-form-ul" style="padding-left:80px;">
                <li class="uhead"><span class="tit">会员头像<i class="abe-red">*</i></span>
                    <div class="info clearfix">
                        <div class="up-img">
                            <span><em>修改头像</em></span>
                            <input onchange="changepic(this)" type="file" id="cudtomerimg">
                            <img id="costomerphoto" src="">
                        </div>
                    </div>
                </li>
                <li><span>会员名称<i class="abe-red">*</i></span></li>
                <li>
                    <input type="text" class="text" id="name">
                </li>
                <li><span>手机号<i class="abe-red">*</i></span></li>
                <li>
                    <input type="text" class="text" id="mobile">
                </li>
                <li><span>邮箱<i class="abe-red">*</i></span></li>
                <li>
                    <input type="text" class="text" id="email">
                </li>

                <li><span>年龄<i class="abe-red">*</i></span></li>
                <li>
                    <input type="text" class="text" id="age">
                </li>
                <li><span>性别<i class="abe-red">*</i></span></li>
                <li>
                    <input type="text" class="text" id="gender">
                </li>
                <li><span>地址<i class="abe-red">*</i></span></li>
                <li>
                    <input type="text" class="text" id="address">
                </li>
                <li><span>兴趣<i class="abe-red">*</i></span></li>
                <li>
                    <input type="text" id="interest" class="text">
                </li>
                <li><span>会员等级<i class="abe-red">*</i></span></li>
                <li>
                    <select id="level">
                        <option value="">请选择</option>
                        <option value="1">普通会员</option>
                        <option value="2">白银会员</option>
                        <option value="3">黄金会员</option>
                        <option value="4">铂金会员</option>
                    </select>
                </li>

                <li><span>标签<i class="abe-red">*</i></span></li>
                <li>
                    <input type="text" class="text" onclick="tagswindow()" id="tags">
                    <button style="height: 38px" onclick="addtagscustomer()">新增标签</button>
                </li>


                <li class="com-submit pdt_10">

                    <input type="button" class="vi-btn-green" onclick="affirm()" value="确认修改">
                    <input type="button" class="vi-btn-orange mlg_15" onclick="cancel()" value="取消修改">
                </li>
            </ul>
            <div class="blank30"></div>

        </div>
    </div>


    <div class="popup-win add-sb" id="tagslist" style="display: none;height: auto;border: #06b3be solid 1px">

        <div class="pop-tit abe-ofl"><span class="abe-fl tit">选择标签</span>
            <a href="#" class="close iconfont abe-fr" onclick="guanbi()">&#xe602;</a></div>

        <div style="padding-top: 20px;"><font color="red" size="2">用户标签：(双击删除)</font></div>

        <!--我的标签-->
        <ul class="mod-cc abe-ofl" id="mytags"></ul>
        <hr>
        <font color="red" size="2">全部标签：(双击添加)</font>

        <!--数据库中的标签-->
        <ul class="mod-cc abe-ofl" id="dbtags"></ul>


        <div style="position:relative;" align="center">
            <input type="button" class="vi-btn-green" onclick="affirm()" value="确认修改">
            <input type="button" class="vi-btn-orange mlg_15" onclick="guanbi()" value="取消修改">
        </div>
    </div>


    <div class="popup-win group-pop" style="display:none ;height: 300px;border: #06b3be solid 1px" id="addtagscustom">
        <div class="pop-tit abe-ofl"><span class="abe-fl tit">添加标签</span> <a href="#" class="close iconfont abe-fr"
                                                                             onclick="closeaddgrouping()">&#xe602;</a>
        </div>
        <ul class="user-form-ul pdl_40" style="display: ;padding-top: 50px" id="ullist">
            <li><span>标签名称：<i class="abe-red"></i></span></li>
            <li>
                <input type="text" id="tagsname" class="text">
            </li>
            <li><span>客户名字：<i class="abe-red"></i></span></li>
            <li>
                <input type="text" disabled="true" id="customername" class="text">
            </li>
        </ul>
        <div class="pop-sub">
            <input type="button" class="vi-btn-green mrg_20" onclick="addtagscustomercommit()" value="确定">
            <input type="button" class="vi-btn-gray" onclick="closeaddgrouping()" value="取消">
        </div>
    </div>

    <div class="popup-bg" style="display:none;z-index: 0" id="mask"></div>

</div>


<div class="icp">Copyright © 2006 - 2015 人脸识别系统版权所有 沪ICP备 0000001号</div>
</body>
</html>
